<?php
	class XMLArray {
		private $dom = null ;
		private $doc = null ;
		private $file = "" ;
		public function getLanguage( $language ){
			$this->file = $language ;
			$this->dom = new DOMDocument("1.0","UTF-8" );
			if ( Basic::fileExist( APP_LOCALE_FOLDER . $this->file . ".lcl" ) ){
				$this->dom->load( APP_LOCALE_FOLDER . $this->file . ".lcl" );
				//print_r( $this->dom->childNodes->item(0) );
				$this->doc = $this->dom->childNodes->item(0);
				return $this->xmlToArray( $this->doc );
			}
			return array();
		}
		
		private function xmlToArray(DOMNode $node = null){
			$result = array();
			$group = array();
			$attrs = null;
			$children = null;
		
			if($node->hasAttributes()){
				$attrs = $node->attributes;
				foreach($attrs as $k => $v){
					$result[$v->name] = $v->value;
				}
			}
		
			$children = $node->childNodes;
		
			if(!empty($children)){
				if((int)$children->length === 1){
					$child = $children->item(0);
					if($child !== null && $child->nodeType === XML_TEXT_NODE){
						$result['#value'] = $child->nodeValue;
						if(count($result) == 1){
							return $result['#value'];
						}
						else{
							return $result;
						}
					}
				}
		
				for($i = 0; $i < (int)$children->length; $i++){
					$child = $children->item($i);
					if($child !== null && ( $child->nodeName != "#text" ) ){
						if(!isset($result[$child->nodeName]) ){
							$result[$child->nodeName] = $this->xmlToArray($child);
						}
						else{
							if(!isset($group[$child->nodeName])){
								$result[$child->nodeName] = array($result[$child->nodeName]);
								$group[$child->nodeName] = 1;
							}
							$result[$child->nodeName][] = $this->xmlToArray($child);
						}
					}
				}
			}
			return $result;
		}
	}
?>